//
//  ArtView.m
//  EasyToo
//
//  Created by Jr Lan on 13-9-2.
//
//

#import "ArtView.h"
#import "DeviceUtil.h"


@implementation ArtView
{
    id<artTimeViewDelegate> _timedelegate;
    id<artTypeViewDelegate> _typedelegate;

    UISegmentedControl *_segment;
    ArtTimeView *_timeView;
    ArtTypeView *_typeView;
    
    BOOL _segFlag;
}

- (void)dealloc
{
    [_segment release];
    [_timeView release];
    [_typeView release];
    
    _segment = nil;
    _timeView = nil;
    _typeView = nil;
    [super dealloc];
    
}

- (id)initWithFrame:(CGRect)frame andDelegate:(id<artTimeViewDelegate>)timedelegate typeDelegate:(id<artTypeViewDelegate>)typedelegate
{
    _timedelegate = timedelegate;
    _typedelegate = typedelegate;
    
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        ArtManager *artmanager = [ArtManager shareManager];
        artmanager.delegate = self;
        [artmanager qryAllArtInfo];

        //初始化视图
        [self init_view];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

//初始化视图
- (void)init_view
{
    [self initTypeView];
//    [self initTimeView];
//    [self initTypeView];
//    
//    [self initSegmentCtrl];
//    [self addTimeView];
}

//初始化SegmentCtrl
- (void)initSegmentCtrl
{
    _segment = [[UISegmentedControl alloc] initWithFrame:CGRectMake(0, 0, [DeviceUtil getScreenWidth], 30)];
    
    [_segment setSegmentedControlStyle:UISegmentedControlStyleBar];
    [_segment setBackgroundColor:[UIColor lightGrayColor]];
    [_segment insertSegmentWithTitle:@"演出时间" atIndex:0 animated:NO];
    [_segment insertSegmentWithTitle:@"演出类别" atIndex:1 animated:NO];
    
    [_segment addTarget:self action:@selector(onTabSelected:) forControlEvents:UIControlEventValueChanged];
    
    [self addSubview:_segment];
}

-(void)onTabSelected:(id)sender
{
    UISegmentedControl *control = (UISegmentedControl *)sender;
    
    switch (control.selectedSegmentIndex) {
        case 0:
            [self addTimeView];
            [self removeTypeView];
            break;
        case 1:
            [self removeTimeView];
            [self addTypeView];
            break;
        default:
            break;
    }
    
}

//演出时间
- (void)initTimeView
{
    float height = IOS7_OR_MORE?44.0:0.0f;
    _timeView = [[ArtTimeView alloc] initWithFrame:CGRectMake(0, 0, [DeviceUtil getScreenWidth], [DeviceUtil getScreenHeight] - height - 90) andDelegate:_timedelegate];
}
- (void)addTimeView
{
    if (_timeView)
    {
        _segFlag = 0;
        [self addSubview:_timeView];
    }
}
- (void)removeTimeView
{
    if (_timeView)
    {
        [_timeView removeFromSuperview];
    }
}

//演出类别
- (void)initTypeView
{
    float height = IOS7_OR_MORE?44.0:0.0f;
    _typeView = [[ArtTypeView alloc] initWithFrame:CGRectMake(0, 0, [DeviceUtil getScreenWidth], [DeviceUtil getScreenHeight] - height - 90) andDelegate:_typedelegate];
}
- (void)addTypeView
{
    if (_typeView)
    {
        _segFlag = 0;
        [self addSubview:_typeView];
    }
}
- (void)removeTypeView
{
    if (_typeView)
    {
        [_typeView removeFromSuperview];
    }
}


//查询所有门票
- (void)qryAllArtInfo:(BOOL)isSuccess artInfo:(AllArtInfo*)artArray
{
    _typeView.allArtInfo = artArray;
    [self addTypeView];
}

@end


